home *** CD-ROM | disk | FTP | other *** search
/ 10,000 Great Games / 10,000 Great Games.iso / Product / 66 / data1.cab / Source_Files / Src / Catapult.cpp < prev    next >
C/C++ Source or Header  |  2000-01-16  |  2KB  |  101 lines

  1. #include "stdafx.h"
  2.  
  3. cCatapult::cCatapult(int _x, int _y, cProperties *_orig)
  4.         : cStructure(_x, _y, _orig)
  5. {
  6.     angle = orig->params->get_fix("*ANGLE", 64);
  7.     range = orig->params->get_int("*RANGE", 150);
  8.     max_speed = orig->params->get_int("*MAX_SPEED", 0);
  9.     max_acceleration = orig->params->get_int("*MAX_ACCELERATION", 250);
  10.     height_to_activate = orig->params->get_int("*HEIGHT_TO_ACTIVATE", GAME_DY);
  11.     push_granularity = orig->params->get_fix("*PUSH_GRANULARITY", 0.2);
  12.     limit_speed = orig->params->get_bool("*LIMIT_SPEED", FALSE);
  13.     
  14.     orig->get_sequence("INACTIVE", inactive_seq);
  15.     orig->get_sequence("ACTIVE", active_seq);
  16.  
  17.     // Check if there's an inactive sequence
  18.  
  19.     if (inactive_seq.start_frame == 0)
  20.     {
  21.         active = TRUE;
  22.         set_sequence(active_seq, TRUE);        
  23.     }
  24.     else
  25.     {
  26.         active = FALSE;
  27.         set_sequence(inactive_seq);        
  28.     }
  29. }
  30.  
  31. int cCatapult::do_catapult(cMovable *_c, cDisplayable *_g, cCircle *, cCircle *)
  32. {
  33.     cCatapult *c = (cCatapult *)_c;
  34.     cGameObject *g = (cGameObject *)_g;
  35.  
  36.     // Check if this object is influenced by catapults
  37.  
  38.     if (!g->influenced_by_catapult)
  39.         return FALSE;
  40.  
  41.     // Compute acceleration
  42.  
  43.     int d = (int)sqrt(d_square(g->x - c->x, g->y - c->y)),
  44.         a = c->max_acceleration * (c->range - d) / c->range,
  45.         v = c->max_speed * (c->range - d) / c->range;
  46.     
  47.     // Push object
  48.  
  49.     if (a > 0)
  50.         g->new_angular_push(c->push_granularity, 0, a, c->angle);
  51.  
  52.     if (v > 0)
  53.     {
  54.         if (c->limit_speed)
  55.         {
  56.             if ((fix)v > g->get_speed(c->angle))
  57.                 g->add_angular_speed((fix)v - g->get_speed(c->angle), c->angle);
  58.         }
  59.         else
  60.         {
  61.             g->add_angular_speed(v, c->angle);
  62.         }
  63.     }
  64.         
  65.     return TRUE;
  66. }
  67.  
  68. int cCatapult::control()
  69. {    
  70.     cGameObject::control();
  71.  
  72.     // Activate catapult
  73.  
  74.     if (!active && animation_done())
  75.     {
  76.         active = y2 - surface->start < height_to_activate;
  77.         set_sequence(active? active_seq : inactive_seq);
  78.     }
  79.     
  80.     // Do active thing
  81.     
  82.     if (active)
  83.     {        
  84.         if (animation_done())
  85.         {
  86.             active = FALSE;
  87.             set_sequence(inactive_seq);            
  88.         }
  89.         else if (!push_wait)
  90.         {
  91.             check_radial_boundaries(circle_bounds, players, do_catapult);
  92.             check_radial_boundaries(circle_bounds, weapons, do_catapult);
  93.             check_radial_boundaries(circle_bounds, bonus, do_catapult);
  94.             
  95.             push_wait = push_granularity * sec;
  96.         }
  97.     }
  98.     
  99.     return !below_screen();
  100. }
  101.